﻿using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Reflection;

namespace SimpleORM
{
    public abstract class DReader
    {
        #region Properties

        public TypeConverter TypeConverter { get; private set; }

        #endregion

        #region Fields

        private Hashtable rds;

        #endregion

        #region Ctor

        public DReader()
        {
            rds = DReaderAttribute.CreateReaders(this.GetType());
            TypeConverter = OnCreateTypeConverter();
        }

        #endregion

        #region Methods

        #region Methods - Public

        public virtual object GetValue(object data, object columnParameter)
        {
            return GetValue(data, columnParameter, null);
        }

        public virtual object GetValue(object data, object columnParameter, object columnType)
        {
            if (!rds.ContainsKey(columnType))
                return null;

            return (rds[columnType] as MethodInfo).Invoke(null, new object[] { data, columnParameter });
        }

        public virtual DataTable GetTable(object data)
        {
            return null;
        }

        public virtual List<Dictionary<string, object>> GetDictionary(object data)
        {
            return null;
        }

        public virtual IList GetObjects(object data, ObjectContext oc)
        {
            return null;
        }

        //public virtual Geometry CreateGeometry(object instance)
        //{
        //    throw new NotSupportedException();
        //}

        //public virtual Geometry CreateGeometry(string geoText)
        //{
        //    throw new NotSupportedException();
        //}

        //public virtual Geometry CreatePolygon(Point[] points)
        //{
        //    throw new NotSupportedException();
        //}

        //public virtual Geometry CreatePolygon(Point[] points, int srid)
        //{
        //    throw new NotSupportedException();
        //}

        #endregion

        #region Methods - Protected

        protected virtual TypeConverter OnCreateTypeConverter()
        {
            return null;
        }

        #endregion

        #endregion
    }
}
